package cn.adley.crawler.service;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class CrawlService {
    @Autowired
    private RestTemplate restTemplate;

    public void crawPage(String url) {
        Document doc = Jsoup.parse(restTemplate.getForObject(url, String.class));
        Elements els = doc.select("a");
        for(Element e : els) {
            log.info("{}",e.attr("href"));
        }
    }
}
